import { getSkuVolumnByCalculate } from '@/utils/getUtils';
import { saleRestrictOptions } from '@/pages/commodity/modules/constants/skuInfoModule/skuOptionsList';
import { WHETHER_OPTIONS } from '@/constants/basics';
import { COOPREATION_MODE_OPTIONS, DEAL_MODE_OPTIONS } from '@/constants/commodity';
import { getAttributeValueList, getRealtimeSpecModel } from '../utils';
import PopoverColumn from '@/components/ShowContent/PopoverColumn';

const SALE_RESTRICT_OPTIONS = saleRestrictOptions.map(item => ({ ...item, value: Number(item.value) })) // 需要转为number类型给潜在使用

const inputAttrs = {
  width: 100,
  type: 'inputNoLimit',
  size: 'mini',
}

const inputNumAttrs = {
  width: 120,
  type: 'inputNumChange',
  size: 'mini',
  controls: false
}

const selectAttrs = {
  width: 100,
  type: 'selectChange',
  size: 'mini',
  clearable: true
}

// 通用弹框组件配置属性
export const COMMON_COMP_CONFIGS = {
  visible: false, // 弹框开关
  curIndex: null, // 当前表格点击行下标
  open: function (index) { // 打开方法
    this.visible = true
    this.curIndex = index ?? null
  },
  resetIndex: function () {
    this.curIndex = null
  }
}

// 异常提示表列项
export const TIPS_COLUMN = {
  title: '异常提示',
  key: 'errorMsg',
  fixed: 'left',
  sortable: true,
  notShowTip: true,
  width: 100,
  render: (h, { row }) => (
    <PopoverColumn
      content-color="#f56c6c"
      content={row.errorMsg}
      dataList={row.errorMsg?.split(';')}
    />
  )
}

// 图文是否必填
export const IMAGE_REQUIRE_ENUMS = {
  Yes: 18913, // 图文必填
  No: 18914 // 图文非必填
}

// 图文是否必填文本
export const IMAGE_REQUIRE_LABELS = {
  [IMAGE_REQUIRE_ENUMS.Yes]: '必填',
  [IMAGE_REQUIRE_ENUMS.No]: '非必填'
}

export const MANAGE_TABLE_COLUMNS = [
  {
    title: 'SKU编码',
    key: 'skuNo',
  },
  {
    title: '末级分类',
    key: 'categoryName',
    ...inputAttrs,
    suffixIcon: 'el-icon-search',
    required: true
  },
  {
    title: '归类名称',
    key: 'classificationName',
    required: true
  },
  {
    title: '税类代码',
    key: 'taxCateNo',
  },
  {
    title: '销售税率',
    key: 'taxRate',
  },
  {
    title: '品牌',
    key: 'brandName',
    ...inputAttrs,
    suffixIcon: 'el-icon-search',
    required: true
  },
  {
    title: '系列',
    key: 'seriesUuid',
  },
  {
    title: '商品名称',
    key: 'productName',
    ...inputAttrs,
    width: 160,
    maxlength: 30,
    required: true,
    notShowTip: true
  },
  {
    title: '规格',
    render: (h, { row }) => {
      const specModel = getRealtimeSpecModel(row)
      row.originalSpecModel = specModel
      return <span>{specModel}</span>
    }
  },
  {
    title: '材质',
    key: 'material',
    ...inputAttrs,
  },
  {
    title: '计量单位',
    key: 'unitName',
  },
  {
    title: '进价',
    key: 'purchasePrice',
    ...inputNumAttrs,
    precision: 3
  },
  {
    title: '成本价',
    key: 'costPrice',
    ...inputNumAttrs,
    precision: 3
  },
  {
    title: '售价',
    key: 'sellPrice',
    ...inputNumAttrs,
    precision: 2
  },
  {
    title: '件装数量',
    key: 'pieceInfo',
    ...inputAttrs,
    width: 160,
    maxlength: 100
  },
  {
    title: '包装清单',
    key: 'packageContents',
    ...inputAttrs,
    width: 160,
    maxlength: 100
  },
  {
    title: '国标条形码 ',
    key: 'barcode',
    ...inputAttrs,
    width: 160,
    maxlength: 100
  },
  {
    title: '经营模式',
    key: 'dealMode',
    ...selectAttrs,
    options: DEAL_MODE_OPTIONS,
  },
  {
    title: '合作模式',
    key: 'cooperationMode',
    ...selectAttrs,
    options: COOPREATION_MODE_OPTIONS,
  },
  {
    title: '厂家编码',
    key: 'factoryCode',
    ...inputAttrs,
    width: 160,
    maxlength: 100
  },
  {
    title: '产地',
    key: 'producingAreaName',
    ...inputAttrs,
    suffixIcon: 'el-icon-search',
  },
  {
    title: '最长边(cm)',
    key: 'edge1',
    ...inputNumAttrs,
  },
  {
    title: '次长边(cm)',
    key: 'edge2',
    ...inputNumAttrs,
  },
  {
    title: '最短边(cm)',
    key: 'edge3',
    ...inputNumAttrs,
  },
  {
    title: '体积(m³)',
    // key: 'volume',
    render: (h, { row }) => <span>{getSkuVolumnByCalculate({ row })}</span>
  },
  {
    title: '重量(kg)',
    key: 'weight',
    ...inputNumAttrs,
  },
  {
    title: '是否定制',
    key: 'canCustom',
    ...selectAttrs,
    options: WHETHER_OPTIONS
  },
  {
    title: '特殊要求说明',
    key: 'note',
    ...inputAttrs,
  },
  {
    title: '售卖平台',
    key: 'salePlatCodes',
    ...selectAttrs,
    width: 150,
    multiple: true,
    options: []
  },
  {
    title: '销售区域',
    key: 'saleAreaStr',
    ...inputAttrs,
    suffixIcon: 'el-icon-search',
    required: true
  },
  {
    title: '数量小数位',
    key: 'decimalPlaces',
    ...inputNumAttrs,
    precision: 0,
    maxVal: 3
  },
  {
    title: '最小起售量',
    key: 'saleMin',
    ...inputAttrs,
    required: true
  },
  {
    title: '销售限制类型',
    key: 'saleResType',
    ...selectAttrs,
    options: SALE_RESTRICT_OPTIONS,
    required: true
  },
  {
    title: '到货周期',
    key: 'arrivalPeriod',
    ...inputNumAttrs,
    precision: 2
  },
  {
    title: '创建人',
    key: 'operName',
  },
  {
    title: '创建时间',
    key: 'opeTime',
  },
  {
    title: '创建人部门',
    key: 'operDeptName',
  },
  {
    title: '商品管理区域',
    key: 'manageAreaName',
  },
  {
    title: '规格属性',
    type: 'slot',
    slotName: 'specAttrs',
    required: true,
    fixed: 'right'
  },
  {
    title: '基本属性',
    type: 'slot',
    slotName: 'basicAttrs',
    required: true,
    fixed: 'right'
  },
  {
    title: '图文完善状态',
    key: 'imageStatusStr',
    type: 'slot',
    fixed: 'right'
  },
]

export const EDIT_UUIDS_KEY = 'latent-batch-edit-uuids'
